package com.wondersgroup.robot.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.wondersgroup.robot.po.UserFavoritesList;

/**
 * Data access object (DAO) for domain model class UserFavoritesList.
 * 
 * @see com.wondersgroup.robot.po.UserFavoritesList
 * @author MyEclipse Persistence Tools
 */

public class UserFavoritesListDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory
			.getLog(UserFavoritesListDAO.class);

	// property constants
	public static final String UFL_NAME = "uflName";

	public static final String UFL_PIC_URL = "uflPicUrl";

	public static final String UFL_LINK_URL = "uflLinkUrl";

	public static final String UFL_ORDER_NUM = "uflOrderNum";

	public void save(UserFavoritesList transientInstance) {
		log.debug("saving UserFavoritesList instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(UserFavoritesList persistentInstance) {
		log.debug("deleting UserFavoritesList instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public UserFavoritesList findById(java.lang.String id) {
		log.debug("getting UserFavoritesList instance with id: " + id);
		try {
			UserFavoritesList instance = (UserFavoritesList) getSession().get(
					"com.wondersgroup.robot.po.UserFavoritesList", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(UserFavoritesList instance) {
		log.debug("finding UserFavoritesList instance by example");
		try {
			List results = getSession().createCriteria(
					"com.wondersgroup.robot.po.UserFavoritesList").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding UserFavoritesList instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from UserFavoritesList as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUflName(Object uflName) {
		return findByProperty(UFL_NAME, uflName);
	}

	public List findByUflPicUrl(Object uflPicUrl) {
		return findByProperty(UFL_PIC_URL, uflPicUrl);
	}

	public List findByUflLinkUrl(Object uflLinkUrl) {
		return findByProperty(UFL_LINK_URL, uflLinkUrl);
	}

	public List findByUflOrderNum(Object uflOrderNum) {
		return findByProperty(UFL_ORDER_NUM, uflOrderNum);
	}

	public List findAll() {
		log.debug("finding all UserFavoritesList instances");
		try {
			String queryString = "from UserFavoritesList";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public UserFavoritesList merge(UserFavoritesList detachedInstance) {
		log.debug("merging UserFavoritesList instance");
		try {
			UserFavoritesList result = (UserFavoritesList) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(UserFavoritesList instance) {
		log.debug("attaching dirty UserFavoritesList instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(UserFavoritesList instance) {
		log.debug("attaching clean UserFavoritesList instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}